using Domain.Dto;
using Gmmy.DomainExtension;
using System;
using System.Linq.Expressions;
using Infrastructure.Common.Enums;

namespace Domain.Specification
{
    public class UserListSpecification : Specification<UserListInput>
    {
        public string LoginName { get; set; }
        public string PassWord { get; set; }
        public string NickName { get; set; }
        public EnumUserState? State { get; set; }


        public UserListSpecification(UserListInput input)
        {
            LoginName = input.LoginName;
            NickName = input.NickName;
            State = input.State;

        }

		/// <summary>
        /// 查询规约
        /// </summary>
        /// <returns></returns>
        public override Expression<Func<UserListInput, bool>> SatisfiedBy()
        {
            var where = PredicateBuilder.True<UserListInput>().And(x => !x.IsDeleted);
            if (!string.IsNullOrEmpty(LoginName))
            {
                where = where.And(x => x.LoginName.Contains(LoginName));
            }
            if (!string.IsNullOrEmpty(NickName))
            {
                where = where.And(x => x.NickName.Contains(NickName));
            }
            if (State != null)
            {
                where = where.And(x => x.State == State);
            }

            return where;
        }
    }
}
